#include <iostream>
using std::cout;
using std::endl;

class Point {
public:
    Point(int x,int y)
    : _ix(x)
    , _iy(y)
    {
        cout << "Point(int,int)" << endl;
    }

    Point(const Point & rhs)
    : _ix(rhs._ix)
    , _iy(rhs._iy)
    {
        cout << "Point(const Point &)" << endl;
    }

    //成员函数的参数列表首位会被编译器自动加上一个参数：this指针
    //作用：指向本对象，准确访问本对象的成员
    //形式：Point * const this
    //位置：成员函数参数列表首位，不能显式写出
    Point & operator=(const Point & rhs){
        this->_ix = rhs._ix;
        this->_iy = rhs._iy;
        cout << "Point& operator=(const Point &)" << endl;
        return *this;//返回本对象
    }

    ~Point(){
        cout << "~Point()" << endl;
    }

	void print()
	{
        /* cout << &this << endl; */
        /* cout << this << endl; */
		cout << "(" << this->_ix 
            << "," << this->_iy
			<< ")" << endl;
	}
private:
	int _ix;
	int _iy;
};

void test0()
{
    Point pt(1,2);
    Point pt2(3,4);
    pt2 = pt; //赋值操作
    //pt2.operator=(pt);//上一句的本质
    pt2.print();
    /* cout << &pt2 << endl; */

    cout << endl;

    int a = 1,b = 2,c = 3;
    c = a = b;


    Point pt3(10,20);
    pt3 = pt2 = pt;
    pt3.print();
    
}

void test1(){
    Point * p = new Point(1,2);
    delete p;
    p->print();
    (*p).print();
}

int main(void){
    test0();
    return 0;
}
